package vue.panneau1;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.TableCellRenderer;
import modele.*;

public class CellRendererJTableEquation implements TableCellRenderer
{
	private TableModelEquation tmEquations;
	private boolean is3D;
	
	public CellRendererJTableEquation(TableModelEquation tmEquations,boolean is3D)
	{
		this.tmEquations = tmEquations;
		this.is3D = is3D;
	}
	
	public Component getTableCellRendererComponent(
			JTable table, 
			Object obj, 
			boolean isSelected, 
			boolean hasFocus, 
			int row, 
			int column)
	{
		Component co = null;
		if(column == 0)
		{
			int nb = tmEquations.getRowCount();						
			boolean trouve = false;
			int i = 0;
			while(i<nb && !trouve)
			{
				if(row == i)
				{
					JTextField jtf = new JTextField();
					jtf.setText((String)obj);
					if(is3D)
					{
						Equation3D eq = tmEquations.getEquation3DAt(row);
						if(!eq.getLibelle().equals("defaut"))
						{
							jtf.setToolTipText(eq.getLibelle());
						}
					}
					else
					{
						Equation2D eq = tmEquations.getEquation2DAt(row);
						if(!eq.getLibelle().equals("defaut"))
						{
							jtf.setToolTipText(eq.getLibelle());
						}
					}				
					trouve = true;
					co = jtf;					
				}
				else i++;
			}
			if(isSelected)
			{
				co.setBackground(Color.LIGHT_GRAY);
			}
		}
		if(column == 1)
		{
			JTextField jtf = new JTextField();
			jtf.setText("");
			jtf.setBackground((Color)obj);
			co = jtf;
		}
		return co;
	}
}
